
var mtournament = {
	events: {
		methods: {
			login: {
				selector: '.js-click-login',
				type: 'click',
				execute: function (e) {
					$(this).closest('form').submit();
				}
			},
			loginPopup: {
				selector: '.js-click-loginPopup',
				type: 'click',
				execute: function (e) {
					var popup = $(this).data('popup');
					$(popup).fadeIn(500);
				}
			}
		}
	}
};

mtournament.events.load = function (scope) {
	var method;
	if (scope===undefined) { scope = document; }
	for(var m in mtournament.events.methods) {
		method = mtournament.events.methods[m];
		$(scope).find(method.selector).each(function (i) {
			$(this).bind(method.type, { method: method }, method.execute);
		});
	}
}

$(document).ready(function () {
	mtournament.events.load();
	
	$('.popup .close').click(function (e) {
		$(this).closest('.popup').fadeOut(500);
	});
	
	$('form').validate({
		errorPlacement: function(error, element) {
			var li = $(element).parent('li');
			li.find('.errmsg').append(error);
		},
		highlight: function (element, errorClass) {
			var li = $(element).parent('li');
			if (!li.is('.error')) {
				li.addClass('error'); 
				li.find('.errast').text('*');
			}
		},
		unhighlight: function (element, errorClass) {
			var li = $(element).parent('li');
			if (li.is('.error')) { 
				li.removeClass('error'); 
				li.find('.errast').text('');
			}
		}
	});
});